<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <child @senddata="getData"></child>
    </div>
    <script src="./vue.js"></script>
    <script>
        const child = {
            template:  `
                <div>
                    这是子组件
                    <button @click="sendData">点击传递数据给父组件</button>
                </div>
            `,
            data() {
                return {
                    msg: '这是要传递给父组件的数据'
                }
            },

            methods: {
                sendData() {
                    this.$emit('senddata', this.msg)
                }
            }
        }
        Vue.component('child', child)
        new Vue({
            data:{
                msg: ''
            },
            mounted() {
                console.log(this.$children[0].msg)
            },
            methods: {
                getData(data) {
                    console.log(data)
                }
            }
        }).$mount('#app')
    </script>
</body>
</html>